package com.yb.login.center.util;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.asymmetric.RSA;
import com.yb.core.util.YbSecureUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * Copyright (C), 2022-2022, 姚兵
 * Author: 32210
 * Date: 2022/12/7 16:44
 * FileName: LoginSecure
 * Description:
 */
@Component
@Slf4j
public class LoginSecure {
    @Autowired
    RSA rsaLogin;

    public class Config{
        private Integer rsaType;
        private RSA rsa;
    }

    @Getter
    @AllArgsConstructor
    public enum AlgoType{
        RSA(0,"beanName");

        private Integer type;
        private String beanName;


    }

    public void encPriDecPub(String content){
        String encrstr = encryptPrivate(content);
        System.out.println(encrstr);
        System.out.println(decryptPublic(encrstr));
    }


    public  void encPubDecPri(String content){
        String encrstr = encryptPublic(content);
        System.out.println(encrstr);
        System.out.println(decryptPrivate(encrstr));
    }
    public  String encryptPrivate(String content){
        return YbSecureUtil.encryptRSAPrivate(rsaLogin,content);
    }

    public  String decryptPublic(String content){
        return YbSecureUtil.decryptRSAPublic(rsaLogin,content);
    }

    public  String encryptPublic(String content){
        return YbSecureUtil.encryptRSAPublic(rsaLogin,content);
    }

    public  String decryptPrivate(String content){
        return YbSecureUtil.decryptRSAPrivate(rsaLogin,content);
    }

    public static void main(String[] args) {
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String admin = SecureUtil.md5("admin");
        String user = SecureUtil.md5("user");
        System.out.println(admin);
        System.out.println(user);
        String adminEn = bCryptPasswordEncoder.encode(admin);//admin
        String userEn = bCryptPasswordEncoder.encode(user);//user
        System.out.println(adminEn);
        System.out.println(userEn);
    }
}
